/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.maxato.services;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ResourceBundle;

import nl.maxato.domain.Athlete;
import nl.maxato.domain.Calendar;
import nl.maxato.domain.Calendar_Week;

/**
 *
 * @author Danny
 */
public class CalculateGeneralData {

    public CalculateGeneralData() {
    }

    /**
     * 0 - Alle atleten
     * 1 - Geen specialiteit
     * 2 - Sprinters
     * 3 - Middenafstandslopers
     * 4 - Langeafstandslopers
     * 5 - Snelwandelaars
     * 6 - Springers
     * 7 - Werpers
     */
    public int getSpecialtyToInteger(int specialtyText) {
        if (specialtyText == 1) {
            return 0;
        } else if (specialtyText == 2) {
            return 1;
        } else if (specialtyText == 3) {
            return 2;
        } else if (specialtyText == 4) {
            return 3;
        } else if (specialtyText == 5) {
            return 4;
        } else if (specialtyText == 6) {
            return 5;
        } else if (specialtyText == 7) {
            return 6;
        }
        return 7;

    }

    /**
     * 0 - 100 meter
     * 1 - 200 meter
     * 2 - 400 meter
     * 3 - 110 meter horden
     * 4 - 400 meter horden
     * 5 - 800 meter
     * 6 - 1500 meter
     * 7 - 3000 steeplechase
     * 8 - 5000 meter
     * 9 - 10000 meter
     * 10 - Marathon
     * 11 - 10km Snelwandelen
     * 12 - 20km Snelwandelen
     * 13 - 50km Snelwandelen
     * 14 - Hoogspringen
     * 15 - Polstokhoogspringen
     * 16 - Verspringen
     * 17 - Hinkstapspringen
     * 18 - Kogelstoten
     * 19 - Discuswerpen
     * 20 - Kogelslingeren
     * 21 - Speerwerpen
     */
    public int getDisciplineToInteger(int disciplineText) {
        if (disciplineText == 0) {
            return 1;
        } else if (disciplineText == 1) {
            return 4;
        } else if (disciplineText == 2) {
            return 6;
        } else if (disciplineText == 3) {
            return 23;
        } else if (disciplineText == 4) {
            return 25;
        } else if (disciplineText == 5) {
            return 8;
        } else if (disciplineText == 6) {
            return 11;
        } else if (disciplineText == 7) {
            return 19;
        } else if (disciplineText == 8) {
            return 14;
        } else if (disciplineText == 9) {
            return 15;
        } else if (disciplineText == 10) {
            return 53;
        } else if (disciplineText == 11) {
            return 46;
        } else if (disciplineText == 12) {
            return 47;
        } else if (disciplineText == 13) {
            return 72;
        } else if (disciplineText == 14) {
            return 26;
        } else if (disciplineText == 15) {
            return 27;
        } else if (disciplineText == 16) {
            return 28;
        } else if (disciplineText == 17) {
            return 29;
        } else if (disciplineText == 18) {
            return 31;
        } else if (disciplineText == 19) {
            return 32;
        } else if (disciplineText == 20) {
            return 33;
        } else if (disciplineText == 21) {
            return 34;
        } else if (disciplineText == 22) {
            return 80;
        } else if (disciplineText == 23) {
            return 90;
        }
        return 0;
    }

    public String getDisciplineToString(int disciplineInt, ResourceBundle rb) {
        if (disciplineInt == 1) {
            return rb.getString("100METERS");
        } else if (disciplineInt == 4) {
            return rb.getString("200METERS");
        } else if (disciplineInt == 6) {
            return rb.getString("400METERS");
        } else if (disciplineInt == 23) {
            return rb.getString("110METERHURDLES");
        } else if (disciplineInt == 25) {
            return rb.getString("400METERHURDLES");
        } else if (disciplineInt == 8) {
            return rb.getString("800METERS");
        } else if (disciplineInt == 11) {
            return rb.getString("1500METERS");
        } else if (disciplineInt == 19) {
            return rb.getString("3000STEEPLECHASE");
        } else if (disciplineInt == 14) {
            return rb.getString("5000METERS");
        } else if (disciplineInt == 15) {
            return rb.getString("10000METERS");
        } else if (disciplineInt == 53) {
            return rb.getString("MARATHON");
        } else if (disciplineInt == 46) {
            return rb.getString("10KMRACEWALK");
        } else if (disciplineInt == 47) {
            return rb.getString("20KMRACEWALK");
        } else if (disciplineInt == 72) {
            return rb.getString("50KMRACEWALK");
        } else if (disciplineInt == 26) {
            return rb.getString("HIGHJUMP");
        } else if (disciplineInt == 27) {
            return rb.getString("POLEVAULT");
        } else if (disciplineInt == 28) {
            return rb.getString("LONGJUMP");
        } else if (disciplineInt == 29) {
            return rb.getString("TRIPLEJUMP");
        } else if (disciplineInt == 31) {
            return rb.getString("SHOTPUT");
        } else if (disciplineInt == 32) {
            return rb.getString("DISCUSTHROW");
        } else if (disciplineInt == 33) {
            return rb.getString("HAMMERTHROW");
        } else if (disciplineInt == 34) {
            return rb.getString("JAVELINTHROW");
        } else if (disciplineInt == 80) {
            return rb.getString("RELAYS4X100");
        } else if (disciplineInt == 90) {
            return rb.getString("RELAYS4X400");
        }

        return "Fout gegaan bij nummer: " + disciplineInt + "";
    }

    public double getAveragedStatics(List<Athlete> loa, String typeOfStatics) {
        double totaal = 0;
        if (loa != null) {
            for (int i = 0; i < loa.size(); i++) {
                if ("age".equals(typeOfStatics)) {
                    totaal += loa.get(i).getAge();
                }
                if ("wage".equals(typeOfStatics)) {
                    totaal += loa.get(i).getWage();
                }
                if ("maxid".equals(typeOfStatics)) {
                    totaal += loa.get(i).getMaxid();
                }
                if ("experience".equals(typeOfStatics)) {
                    totaal += loa.get(i).getExperience();
                }
                if ("care".equals(typeOfStatics)) {
                    totaal += loa.get(i).getCare();
                }
                if ("mood".equals(typeOfStatics)) {
                    totaal += loa.get(i).getMood();
                }
                if ("form".equals(typeOfStatics)) {
                    totaal += loa.get(i).getForm();
                }
                if ("fans".equals(typeOfStatics)) {
                    totaal += loa.get(i).getFans();
                }
            }
            return totaal = totaal / loa.size();
        }
        return 0;
    }

    public Integer getTotalStatics(List<Athlete> loa, String typeOfStatics) {
        int totaal = 0;
        if (loa != null) {

            for (int i = 0; i < loa.size(); i++) {
                if ("fans".equals(typeOfStatics)) {
                    totaal += loa.get(i).getFans();
                }
                if ("wage".equals(typeOfStatics)) {
                    totaal += loa.get(i).getWage();
                }
                if ("maxid".equals(typeOfStatics)) {
                    totaal += loa.get(i).getMaxid();
                }
                if ("youth".equals(typeOfStatics)) {
                    totaal += loa.get(i).getYouth();
                }
                if ("injuries".equals(typeOfStatics)) {
                    totaal += loa.get(i).getInjury();
                }
            }
        }
        return totaal;
    }

    public ArrayList<String> getNextThreeCompetition(Calendar cv, ResourceBundle rb) {
        ArrayList<Calendar_Week> cwNew = new ArrayList<Calendar_Week>();
        //DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
        for (int i = 0; i < cv.getWeeksCalendar().size(); i++) {
            int year = cv.getWeeksCalendar().get(i).getYearCalendarWeek() - 1900;
            int month = cv.getWeeksCalendar().get(i).getMonthCalendarWeek() - 1;
            int day = cv.getWeeksCalendar().get(i).getDayCalendarWeek();
            java.util.Date date = new Date(year, month, day);
            if (date.after(new Date())) {
                cwNew.add(cv.getWeeksCalendar().get(i));
            }
        }
        return getCompetitionsToString(cwNew, rb);
    }

    public ArrayList<String> getCompetitionsToString(ArrayList<Calendar_Week> cw, ResourceBundle rb) {
        ArrayList<String> competities = new ArrayList<String>();

        for (int i = 0; i < 5; i++) {
            try {
                competities.add(cw.get(i).getDayCalendarWeek() + " "
                        + rb.getString(getNumberToMonth(cw.get(i).getMonthCalendarWeek()))
                        + " " + cw.get(i).getYearCalendarWeek() + "   " + getNumberToCompetition(cw.get(i).getCompetitionCalendarWeek(), rb));
            } catch (Exception ex) {
                competities.add("");
            }
        }

        return competities;
    }

    public String getNumberToMonth(int number) {
        if (number == 1) {
            return "JANUARY";
        }
        if (number == 2) {
            return "FEBRUARY";
        }
        if (number == 3) {
            return "MARCH";
        }
        if (number == 4) {
            return "APRIL";
        }
        if (number == 5) {
            return "MAY";
        }
        if (number == 6) {
            return "JUNE";
        }
        if (number == 7) {
            return "JULY";
        }
        if (number == 8) {
            return "AUGUST";
        }
        if (number == 9) {
            return "SEPTEMBER";
        }
        if (number == 10) {
            return "OCTOBER";
        }
        if (number == 11) {
            return "NOVEMBER";
        }
        if (number == 12) {
            return "DECEMBER";
        }
        return "ERROR";
    }

    public String getNumberToCompetition(ArrayList<Integer> numbers, ResourceBundle rb) {
        String meetings = "";
        for (int i = 0; i < numbers.size(); i++) {
            if (i >= 1) {
                meetings += ", ";
            }
            if (numbers.get(i) == 1) {
                meetings += rb.getString("REGIONAL_MEETING");
            }
            if (numbers.get(i) == 2) {
                meetings += rb.getString("NATIONAL_MEETING");
            }
            if (numbers.get(i) == 3) {
                meetings += rb.getString("CONTINENTAL_MEETING");
            }
            if (numbers.get(i) == 4) {
                meetings += rb.getString("INTERNATIONAL_MEETING");
            }
            if (numbers.get(i) == 5) {
                meetings += rb.getString("CLUB_REGIONAL_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 6) {
                meetings += rb.getString("CLUB_NATIONAL_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 7) {
                meetings += rb.getString("INDIVIDUAL_REGIONAL_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 8) {
                meetings += rb.getString("INDIVIDUAL_NATIONAL_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 9) {
                meetings += rb.getString("CONTINENTAL_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 10) {
                meetings += rb.getString("WORLD_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 11) {
                meetings += rb.getString("CONTINENTAL_JUNIOR_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 12) {
                meetings += rb.getString("CONTINENTAL_MASTERS_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 13) {
                meetings += rb.getString("CHAMPIONS_CUP");
            }
            if (numbers.get(i) == 14) {
                meetings += rb.getString("WORLD_JUNIOR_CHAMPIONSHIPS");
            }
            if (numbers.get(i) == 15) {
                meetings += rb.getString("NATIONAL_LEAGUE");
            }
            if (numbers.get(i) == 16) {
                meetings += rb.getString("OLYMPIC_GAMES");
            }
            if (numbers.get(i) == 17) {
                meetings += rb.getString("WORLD_MASTER_CHAMPIONSHIPS");
            }
        }

        return meetings;
    }
}
